version 8.0
log using cox.log, replace
#delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      cox.do                                          *;
*       Date:           4/15/06                                         *;
*       Author:         MRG                                             *;
*       Purpose:        PA Article using Amorim Neto and Cox 1997 data  *;
*       Input File:     coxappend.dta                                   *;
*       Output File:    cox.log                                         *;
*       Data Output:    coxappend.dta                                   *;
*       Previous file:                                                  *;
*       Machine:                                                        *;
*     ****************************************************************  *;
*     ****************************************************************  *;

set mem 10m;

use "C:\Documents and Settings\matt\My Documents\politicalanalysis\coxappend.dta", clear;

*     ****************************************************************  *;
*           Summary Statistics                                          *;
*     ****************************************************************  *;

sum;


*     ****************************************************************  *;
*                           Dichotomize the Data                        *;
*     ****************************************************************  *;

gen multiparty=.;
replace multiparty=1 if enps>2.99;
replace multiparty=0 if enps<3;

gen multimember=.;
replace multimember=1 if ml>1;
replace multimember=0 if ml==1;

tab multiparty multimember;

*     ****************************************************************  *;
*       Dichotomize eneth 1>median, 0 otherwise.                        *;
*     ****************************************************************  *;

sum eneth, detail;

gen heterogeneity=.;
replace heterogeneity=1 if eneth>1.2775;
replace heterogeneity=0 if eneth<1.2775;

*     ****************************************************************  *;
*       Graph of legislative parties against ln(magnitude).             *;
*     ****************************************************************  *;

graph twoway scatter enps lnml, mlabel(var12) mlabsize(2) msize(1) 
xlabel(0 1 2 3 4 5 6, labsize(2.5)) ylabel(1 3 5 7 9, 
labsize(2.5)) title("Figure 3: The Relationship between Electoral Laws 
and Party System Size", size(4)) xtitle(Log of Median District 
Magnitude, size(3)) ytitle(Effective Number of Legislative Parties, 
size(3)) yline(1 3 5 7 9, lcolor(white)) scheme(s2mono) graphregion(fcolor(white));

*     ****************************************************************  *;
*       Get standard deviations around mean of legislative parties in   *;
*       single member and multi-member districts.                       *;
*     ****************************************************************  *;

sum enps if multi==1;
sum enps if multi==0;

*     ****************************************************************  *;
*       Run regression for results with dichotomous variables.          *;
*     ****************************************************************  *;

gen multi_heterogeneity = multimember*heterogeneity;

regress enps heterogeneity multimember multi_heterogeneity;

*     ****************************************************************  *;
*       Predicted number of parties - homogenous and single-member      *;
*     ****************************************************************  *;

lincom 1*_cons;

*     ****************************************************************  *;
*       Predicted number of parties - heterogeneous and single-member   *;
*     ****************************************************************  *;

lincom 1*_cons + 1*heterogeneity;

*     ****************************************************************  *;
*       Predicted number of parties - homongeous and multi-member       *;
*     ****************************************************************  *;

lincom 1*_cons + 1* multimember;

*     ****************************************************************  *;
*       Predicted number of parties - heterogeneous and multi-member    *;
*     ****************************************************************  *;

lincom 1*_cons + 1* multimember +1*heterogeneity + 1*multi_heterogeneity;

*     ****************************************************************  *;
*       Calculate marginal effects with dichotomous variables           *;
*     ****************************************************************  *;

regress enps heterogeneity multimember multi_heterogeneity;

lincom 1*heterogeneity;

lincom 1*heterogeneity + 1*multi_heterogeneity, level(94);

*     ****************************************************************  *;
*       Run regression for results with continuous variables.           *;
*     ****************************************************************  *;

regress  enps eneth lnml lmleneth;

generate JH=((_n-1)/10);

replace JH=. if _n>52;

matrix b=e(b); 
matrix V=e(V); 
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];
scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];
set more off;

*     ****************************************************************  *;
*         Create full range of marginal effect                          *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<52;
set more off;

*     ****************************************************************  *;
*           Create full range of standard errors                        *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<52; 
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 95% level          *;
*     ****************************************************************  *;

gen a=1.96*conse; 
gen top=conb+a; 
gen bottom=conb-a;
set textsize 100;

graph twoway  line conb JH, clwidth(medium) clcolor(blue) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4 5 , labsize(2.5)) 
            ylabel(-2 0 2 4 , labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Marginal Effect of Social Heterogeneity") label(2 "95% Confidence Interval") 
                  label(3 " "))
        yline(0, lcolor(black)) yline(2 4 , lcolor(white))  
            title("Figure 4: Marginal Effect of Social Heterogeneity", size(4))
            subtitle(" " "Dependent Variable: Effective Number of Legislative Parties" " ", size(3))
            xtitle(Logged Median District Magnitude, size(3)  )
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Marginal Effect of Social Heterogeneity" , size(3))
        scheme(s2mono) graphregion(fcolor(white));



save    cox, replace; exit;
